// pages/my/my.js
var httpTool = require('../../utils/network.js');
var util = require('../../utils/util.js')
const app = getApp()
Page({
  data:{
    cityName: '',
    companyName: '',
    scale: '',
    remark: '',
    contactPerson: '',
    contactPhone: '',
  },
  //页面输入框监听
  onInput: function (event) {
    var viewId = event.currentTarget.dataset.id;
    var inputText = event.detail.value;
    switch (viewId) {
      case 'cityName':
        this.data.cityName = inputText;
        break
      case 'companyName':
        this.data.companyName = inputText;
        break
      case 'scale':
        this.data.scale = inputText;
        break
      case 'remark':
        this.data.remark = inputText;
        break
      case 'contactPerson':
        this.data.contactPerson = inputText;
        break
      case 'contactPhone':
        this.data.contactPhone = inputText;
        break
    }
  },
  //提交冠名申请
  onSubmit: function (event) {
    var viewId = event.currentTarget.dataset.id;
    switch (viewId) {
      case 'applyNamingBtn':  //选择公司
        this.submitApply();
        break
    }
  },
  //提交冠名申请
  submitApply: function () {
    var cityName = this.data.cityName
    var companyName = this.data.companyName
    var scale = this.data.scale
    var remark = this.data.remark
    var contactPerson = this.data.contactPerson
    var contactPhone = this.data.contactPhone

    if (cityName.length == 0) {
      util.fxAlert('请输入拟冠名城市')
      return;
    }
    if (companyName.length == 0) {
      util.fxAlert('请输入企业名称')
      return;
    }
    if (scale.length == 0) {
      util.fxAlert('请输入拟组织大学生规模')
      return;
    }
    // if (remark.length == 0) {
    //   util.fxAlert('请输入备注')
    //   return;
    // }
    if (contactPerson.length == 0) {
      util.fxAlert('请输入联系人')
      return;
    }
    if (contactPhone.length == 0) {
      util.fxAlert('请输入联系人电话')
      return;
    }
    var param = {
      cityName: cityName,
      companyName: companyName,
      scale: scale,
      remark: remark,
      contactPerson: contactPerson,
      contactPhone: contactPhone,
    }
    var that = this;
    httpTool.post({
      url: 'v1/namingApply/create',
      busyText: "请求中...",
      data: param,
      callback: function (res) {
        httpTool.busyClose();
        util.fxAlert(res.msg);
        wx.navigateBack();
      }
    })
  },
  onLoad:function(options){
    // 生命周期函数--监听页面加载
    
  },
  onReady:function(){
    // 生命周期函数--监听页面初次渲染完成
    
  },
  onShow:function(){
    // 生命周期函数--监听页面显示
    
  },
  onHide:function(){
    // 生命周期函数--监听页面隐藏
    
  },
  onUnload:function(){
    // 生命周期函数--监听页面卸载
    
  },
  onPullDownRefresh: function() {
    // 页面相关事件处理函数--监听用户下拉动作
    
  },
  onReachBottom: function() {
    // 页面上拉触底事件的处理函数
    
  },
  onShareAppMessage: function() {
    // 用户点击右上角分享
    return {
      title: 'title', // 分享标题
      desc: 'desc', // 分享描述
      path: 'path' // 分享路径
    }
  }
})
